/*
 * Created on 04.02.2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.jchains.intercept; 

import com.sun.org.apache.bcel.internal.generic.ObjectType;
import com.sun.org.apache.bcel.internal.generic.Type;


/**
 * @author Marc
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class BCELHelper {
	public static Type getType(Class clazz) {

		if (clazz.isPrimitive()) {

			if (clazz.equals(Boolean.TYPE)) {

				return Type.BOOLEAN;

			} else if (clazz.equals(Byte.TYPE)) {

				return Type.BYTE;

			} else if (clazz.equals(Character.TYPE)) {

				return Type.CHAR;

			} else if (clazz.equals(Double.TYPE)) {

				return Type.DOUBLE;

			} else if (clazz.equals(Float.TYPE)) {

				return Type.FLOAT;

			} else if (clazz.equals(Integer.TYPE)) {

				return Type.INT;

			} else if (clazz.equals(Long.TYPE)) {

				return Type.LONG;

			} else if (clazz.equals(Short.TYPE)) {

				return Type.SHORT;

			} else if (clazz.equals(Void.TYPE)) {

				return Type.VOID;

			}

			// should never get here

			throw new IllegalStateException("UnreachableStatementException();"); 

		}

		// if we get this far it is not a primitive

		String name = clazz.getName();

		if (clazz.isArray()) {

			return Type.getType(name);

		}

		return new ObjectType(name);

	}

}
